Skip to content

Ruby refresher done #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Ruby refresher done #2

wants to merge 11 commits into from

Conversation

fabienalbi
Copy link

No description provided.

end

# in a hash where the keys and values are all numbers
# add all the keys and all the values together, e.g.
# {1 => 1, 2 => 2} becomes 6
def add_together_keys_and_values(hash)
hash.flatten.inject{ |sum, ele| sum += ele }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space missing to the left of {.

hash_count[word.length] ||= 0
hash_count[word.length] += 1
end
return hash_count

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant return detected.

end

# return true if the date is a uk bank holiday for 2014
# the list of bank holidays is here:
# https://www.gov.uk/bank-holidays
def is_a_2014_bank_holiday?(date)
bank_holidays_2014 = [Time.new(2014, 1, 1), Time.new(2014, 4, 18), Time.new(2014, 1, 21), Time.new(2014, 5, 5), Time.new(2014, 8, 25), Time.new(2014, 12, 25), Time.new(2014, 12, 26)]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [184/80]

elsif i == 1
puts "1 bottle of beer on the wall, 1 bottle of beer.\nTake one down and pass it around, no more bottles of beer on the wall.\n\n"
else
puts "#{i} bottles of beer on the wall, #{i} bottles of beer.\nTake one down and pass it around, #{i - 1} bottles of beer on the wall.\n\n"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [145/80]

# except 'a', 'and' and 'the'
# *unless* they come at the start of the start of the string, e.g.
# 'the lion the witch and the wardrobe' becomes
# 'The Lion the Witch and the Wardrobe'
def titleize_a_string(string)
string.capitalize.split(' ').each do |ele|
ele.capitalize! unless ['a', 'and', 'the'].index(ele)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use %w or %W for an array of words.

"#{i} bottles of beer.\n"\
"Take one down and pass it around, "\
"#{i - 1} bottles of beer on the wall.\n\n"
puts string

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move puts string out of the conditional.

end

# return true if the date is a uk bank holiday for 2014
# the list of bank holidays is here:
# https://www.gov.uk/bank-holidays
def is_a_2014_bank_holiday?(date)
bank_holidays_2014 = [Time.new(2014, 1, 1), Time.new(2014, 4, 18),
Time.new(2014, 1, 21), Time.new(2014, 5, 5), Time.new(2014, 8, 25),
Time.new(2014, 12, 25), Time.new(2014, 12, 26)]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align the elements of an array literal if they span more than one line.

Time.new(2014, 8, 25),
Time.new(2014, 12, 25),
Time.new(2014, 12, 26)
]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent the right bracket the same as the start of the line where the left bracket is.

end

# return true if the date is a uk bank holiday for 2014
# the list of bank holidays is here:
# https://www.gov.uk/bank-holidays
def is_a_2014_bank_holiday?(date)
bank_holidays_2014 = [

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary spacing detected.
Operator = should be surrounded by a single space.

@bu7ch
Copy link
Member

bu7ch commented Apr 9, 2016

au moins c'est utile à produire du code plus performant...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants